JavaScript Dynamic Document

This stationery page contains JavaScript that creates a dynamic page

Please note that JavaScript is currently only available in Netscape Navigator 2.0 or higher.
Do not assume that all in your audience are using a JavaScript enabled browser.


Here is an example on how JavaScript can be used to provide a dynamic page that will change its contents depending upon the local time specified in the browser's system and the OS that is used by the reader.

Welcome !


How to use:
Four small scripts are embedded inside the text contents of this file. The scripts are executed - and inserts text - when the page is being loaded. View the source file to see how this is done. Every function is commented.

Replace the contents inside the script with calls to your own test functions and add text you want to have displayed inside document.write() function inside the script. It is recommended to create functions for complex scripts and place these in the HEAD section, see the sayHello function for an example of this.

Make sure that all text is placed inside the document.write() function, otherwise it will not look good on browsers that don't support JavaScript.

Edit this page or copy selected scripts to create your own dynamic page!


Example code for the first dynamic text above:

Welcome <B><SCRIPT> <!-- document.write(navigator.userAgent) // --> </SCRIPT></B>! Note that the text "Welcome !" is the only text that will be displayed in browsers that don't support JavaScript.

You may also write the script without the <!-- comment (see below), but if you do this the actual script may show up in a browser that doesn't support JavaScript. This is not recommended:

Welcome, <B><SCRIPT>document.write(navigator.userAgent);</SCRIPT></B>!


This function located in the HEAD section returns true if the browser is running on a Mac:

function isMacintoshBrowser() { return(navigator.appVersion.lastIndexOf('Mac') != -1 ); } The function can be used inside a script like this: if (isMacintoshBrowser()) document.write('Mac specific text...'); else document.write('Text for other platforms...')


Bug note:
In this version of the script I have modified the getTime() so that it will make the time to be displayed correctly in Navigator 3.0 (and 2.0). The time seem to be offset by one hour in the 3.0 version compared to the 2.0 version! This may have something to do with daylight saving time (or maybe not...).